Extended gtk_cell_area_apply_attributes() to account for expander/expanded cells
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 2 Nov 2010 09:01:03 +0000 (18:01 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 2 Nov 2010 09:01:03 +0000 (18:01 +0900)
The state of expanded cells must come from the view, since these states
can vary across views accessing the same model (also "finished up" the
applying of attributes code).

gtk/gtkcellarea.c
gtk/gtkcellarea.h

index e77c2280ce21fbb7d87e3c8d01f215c09fb002b1..634ff4906c70829e194bc986aaa18b94762fbe34 100644 (file)
@@ -117,6 +117,8 @@ typedef struct {
   GtkCellArea  *area;
   GtkTreeModel *model;
   GtkTreeIter  *iter;
+  gboolean      is_expander;
+  gboolean      is_expanded;
 } AttributeData;
 
 struct _GtkCellAreaPrivate
@@ -926,6 +928,22 @@ apply_cell_attributes (GtkCellRenderer *renderer,
   CellAttribute *attribute;
   GSList        *list;
   GValue         value = { 0, };
+  gboolean       is_expander;
+  gboolean       is_expanded;
+
+  g_object_freeze_notify (G_OBJECT (renderer));
+
+  /* Whether a row expands or is presently expanded can only be 
+   * provided by the view (as these states can vary across views
+   * accessing the same model).
+   */
+  g_object_get (renderer, "is-expander", &is_expander, NULL);
+  if (is_expander != data->is_expander)
+    g_object_set (renderer, "is-expander", data->is_expander, NULL);
+  
+  g_object_get (renderer, "is-expanded", &is_expanded, NULL);
+  if (is_expanded != data->is_expanded)
+    g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
 
   /* Apply the attributes directly to the renderer */
   for (list = info->attributes; list; list = list->next)
@@ -942,12 +960,16 @@ apply_cell_attributes (GtkCellRenderer *renderer,
   if (info->func)
     info->func (GTK_CELL_LAYOUT (data->area), renderer,
                data->model, data->iter, info->data);
+
+  g_object_thaw_notify (G_OBJECT (renderer));
 }
 
 void
 gtk_cell_area_apply_attributes (GtkCellArea  *area,
                                GtkTreeModel *tree_model,
-                               GtkTreeIter  *iter)
+                               GtkTreeIter  *iter,
+                               gboolean      is_expander,
+                               gboolean      is_expanded)
 {
   GtkCellAreaPrivate *priv;
   AttributeData       data;
@@ -958,6 +980,13 @@ gtk_cell_area_apply_attributes (GtkCellArea  *area,
 
   priv = area->priv;
 
+  /* Feed in data needed to apply to every renderer */
+  data.area        = area;
+  data.model       = tree_model;
+  data.iter        = iter;
+  data.is_expander = is_expander;
+  data.is_expanded = is_expanded;
+
   /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
    * apply the data from the treemodel */
   g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
index c45977fb292a833ab13faa96126f1a7458a187a5..2e804714c5617e4c0dbcd91d252c52a76b3d097c 100644 (file)
@@ -197,7 +197,9 @@ void               gtk_cell_area_get_preferred_width_for_height (GtkCellArea
 /* Attributes */
 void               gtk_cell_area_apply_attributes               (GtkCellArea        *area,
                                                                 GtkTreeModel       *tree_model,
-                                                                GtkTreeIter        *iter);
+                                                                GtkTreeIter        *iter,
+                                                                gboolean            is_expander,
+                                                                gboolean            is_expanded);
 void               gtk_cell_area_attribute_connect              (GtkCellArea        *area,
                                                                 GtkCellRenderer    *renderer,
                                                                 const gchar        *attribute,